package com.russell.pms.dao.hibernate;

import java.util.List;

import com.russell.pms.dao.DocumentDao;
import com.russell.pms.model.Document;

/**
 * 
 * @author <a href="mailto:fvinluan@gmail.com">Francis Vinluan</a>
 * 
 * @version $Revision: 1.0 $
 */
public class DocumentDaoHibernate extends BaseDaoHibernate implements
		DocumentDao {

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.princess.etrak.dao.DocumentDao#getDocument(java.lang.Short)
	 */
	/**
	 * Method getDocument.
	 * 
	 * @param id
	 *            Long
	 * 
	 * @return Document * @see
	 *         com.princess.etrak.dao.DocumentDao#getDocument(Long) * @see
	 *         com.princess.etrak.dao.DocumentDao#getDocument(String) * @see
	 *         com.princess.etrak.dao.DocumentDao#getDocument(String)
	 */
	public Document getDocument(int id) {
		if (logger.isDebugEnabled()) {
			logger.debug("getting document begins" + id);
		}
		Document document = (Document) getCurrentSession().get(Document.class,
				id);
		if (logger.isDebugEnabled()) {
			logger.debug("getting document ends ");
		}
		return document;
	}

	/**
	 * Gets a list of all document.
	 * 
	 * 
	 * @return List populated list of document * @see
	 *         com.princess.etrak.dao.DocumentDao#getDocumentList() * @see
	 *         com.princess.etrak.dao.DocumentDao#getDocumentList() * @see
	 *         com.princess.etrak.dao.DocumentDao#getDocumentList() * @see
	 *         com.princess.etrak.dao.DocumentDao#getDocumentList()
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<Document> getDocuments() {
		if (logger.isDebugEnabled()) {
			logger.debug("getting all document begins");
		}
		List<Document> cList = getCurrentSession().createQuery("FROM Document")
				.list();
		if (cList == null || cList.size() < 1)
			return null;
		if (logger.isDebugEnabled()) {
			logger.debug("getting all document ends: ");
		}
		return cList;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.princess.etrak.dao.DocumentDao#removeDocument(com.princess.ilo
	 * .model.Document)
	 */
	/**
	 * Method removeDocument.
	 * 
	 * @param document
	 *            Document
	 * 
	 * @see com.princess.etrak.dao.DocumentDao#removeDocument(Document)
	 */
	public void removeDocument(Document document) {
		if (logger.isDebugEnabled()) {
			logger.debug("removeDocument begins");
		}
		getCurrentSession().delete(document);
		if (logger.isDebugEnabled()) {
			logger.debug("removeDocument ends");
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.princess.etrak.dao.DocumentDao#saveDocument(com.princess.etrak.
	 * model.Document)
	 */
	/**
	 * Method saveDocument.
	 * 
	 * @param document
	 *            Document
	 * 
	 * @see com.princess.etrak.dao.DocumentDao#saveDocument(Document)
	 */
	public void saveDocument(Document document) {
		if (logger.isDebugEnabled()) {
			logger.debug("saveDocument begins: " + document);
		}
		getCurrentSession().save(document);
		if (logger.isDebugEnabled()) {
			logger.debug("saveDocument ends");
		}
	}

	/**
	 * Method updateDocument.
	 * 
	 * @param document
	 *            Document
	 * 
	 * @see com.princess.etrak.dao.DocumentDao#updateDocument(Document)
	 */
	@Override
	public void updateDocument(Document document) {
		if (logger.isDebugEnabled()) {
			logger.debug("updateDocument begins: " + document);
		}
		getCurrentSession().update(document);
		if (logger.isDebugEnabled()) {
			logger.debug("updateDocument ends");
		}
	}

}
